<template>
  <view class="cybj-con">
    <view class="main-pd">
      <view class="u-card">
        <view class="font-28 color-595959">表决事项：</view>
        <view class="font-32 color-333 u-m-t-16">
          {{ bjMsg.title || "" }}
        </view>
      </view> 
	  <view class="u-card u-m-t-20" v-if="bjMsg.content">
        <view class="font-28 color-595959">事项描述：</view>
        <view class="font-32 color-333 u-m-t-16">
          {{ bjMsg.content || "" }}
        </view>
      </view>
      <view class="u-card u-m-t-20">
        <view class="font-28 color-595959">表决时间：</view>
        <view class="font-32 color-333 u-m-t-16">
          {{ bjMsg.startTime || "" }} ~ {{ bjMsg.endTime || "" }}
        </view>
      </view>
      <view class="u-card u-m-t-20">
        <view class="font-28 color-595959">表决内容：</view>
        <view
          class="cybj-item"
          v-for="(item, index) in bjMsg.bjsx"
          :key="item.sybjId">
          <view class="font-32 color-333 u-m-t-20">
            {{ index + 1 }}、{{ item.content || "" }}
          </view>
          <view class="u-m-t-20">
            <u-radio-group v-model="item.selectOption" placement="row" :disabled="bjMsg.isYbj==1">
              <u-radio
                activeColor="#f34b47"
                :customStyle="{ marginRight: '48rpx' }"
                v-for="(item2, index2) in item.options.split(',')"
                :key="index2"
                :label="item2"
                :name="item2">
              </u-radio>
            </u-radio-group>
          </view>
        </view>
      </view>
      <view class="u-m-t-84" v-if="bjMsg.isYbj==0">
        <u-button
          text="提交"
          shape="circle"
          color="linear-gradient(90deg, #FA827D 0%, #F34B47 100%)"
          :customStyle="{
            fontSize: '36rpx',
            height: '96rpx',
          }"
          @click="cybj"></u-button>
      </view>
    </view>
  </view>
</template>

<script setup>
import { getwxjjInfoApi, yzbjApi } from "@/api/index";
import { onLoad } from "@dcloudio/uni-app";
import { ref } from "vue";
import useInfoStore from "@/store/user";
const userStore = useInfoStore();
let bjMsg = ref({});
let sxId = ref("");
// 获取详情
const getwxjjInfo = (id) => {
  getwxjjInfoApi({
    id,
    dzyzkId: userStore.dzyzkId,
  }).then((res) => {
    if (res.success) {
      let data = res.data;
      data.bjsx.forEach((item) => {
        item.selectOption = item.selectedOptions?item.selectedOptions:'';
      });
      bjMsg.value = data;
    }
  });
};
// 参与表决
const cybj = () => {
  let bjResult = [];
  bjMsg.value.bjsx.forEach((item) => {
    if (item.selectOption == "") {
      uni.$u.toast("请选择完整！");
      throw new Error("请选择完整");
    }
    bjResult.push({
      bjjg: item.selectOption,
      bjsxId: item.bjsxId,
    });
  });
  yzbjApi({
    bjSx: bjResult,
    dzyzkId: userStore.dzyzkId,
    id: sxId.value,
  }).then((res) => {
    if (res.success) {
      uni.$u.toast("表决成功！");
      return false;
    } else {
      uni.$u.toast(res.msg);
    }
  });
};
onLoad((param) => {
  sxId.value = param.id;
  getwxjjInfo(param.id);
});
</script>

<style lang="scss" scoped>
.cybj-con {
  padding-top: 28rpx;
  padding-bottom: 80rpx;
  .cybj-item {
    border-bottom: 1rpx solid #e6e6e6;
    padding: 28rpx 0;

    &:first-child {
      padding-top: 0;
    }

    &:last-child {
      border: none;
      padding-bottom: 0;
    }
  }
}
</style>
